<?php
/**
 * Created by PhpStorm.
 * User: Dream
 * Date: 2018/2/19
 * Time: 18:37
 */

namespace App\Http\Controllers\Admin;

use App\Base\BaseFunc;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class CheckController extends Controller
{
    public function checkGameJPG()
    {
        $data['gameJPG'] = DB::table('game_jpg')
            ->orderby('game_jpg_status','asc')
            ->paginate(10);
        session(['now_address'=>'/checkGameJPG']);
        return view('admin.hu.checkGameJPG',$data);
    }

    public function gameJPGInfo($game_jpg_id)
    {
        $data['gameJPGInfo'] = DB::table('game_jpg')
            ->where('game_jpg_id',$game_jpg_id)
            ->first();
        return view('admin.hu.gameJPGInfo',$data);
    }

    public function changeGameJPG(BaseFunc $baseFunc)
    {
        $input = Input::only('success');
        $value['game_jpg_status'] = 1;
        //dd($input);
        DB::table('game_jpg')
            ->where('game_jpg_id',$input['success'])
            ->update($value);
        $baseFunc->setRedirectMessage(true,'审核通过',NULL,NULL);
        return redirect()->back();
    }

    public function delGameJPG(BaseFunc $baseFunc)
    {
        $input = Input::only('false');
        $data = DB::table('game_jpg')
            ->where('game_jpg_id','=',$input['false'])
            ->first();
        $fail_name = ".$data->game_jpg_name";
        if(file_exists($fail_name))
        {
            unlink($fail_name);
            DB::table('game_jpg')
                ->where('game_jpg_id',$input['false'])
                ->delete();
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkGameJPG');
        }
        else
        {
            DB::table('game_jpg')
                ->where('game_jpg_id',$input['false'])
                ->delete();
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkGameJPG');
        }
    }

    public function checkUserJPG()
    {
        $data['userJPG'] = DB::table('user_jpg')
            ->orderby('user_jpg_status','asc')
            ->paginate(10);
        session(['now_address'=>'/checkUserJPG']);
        return view('admin.hu.checkUserJPG',$data);
    }

    public function userJPGInfo($user_jpg_id)
    {
        $data['userJPGInfo'] = DB::table('user_jpg')
            ->where('user_jpg_id',$user_jpg_id)
            ->first();
        return view('admin.hu.userJPGInfo',$data);
    }

    public function changeUserJPG(BaseFunc $baseFunc)
    {
        $input = Input::only('success');
        $value['user_jpg_status'] = 1;
        //dd($input);
        DB::table('user_jpg')
            ->where('user_jpg_id',$input['success'])
            ->update($value);
        $baseFunc->setRedirectMessage(true,'审核通过',NULL,NULL);
        return redirect()->back();
    }

    public function delUserJPG(BaseFunc $baseFunc)
    {
        $input = Input::only('false');
        $data = DB::table('user_jpg')
            ->where('user_jpg_id','=',$input['false'])
            ->first();
        $fail_name = ".$data->user_jpg_name";
        if(file_exists($fail_name))
        {
            unlink($fail_name);
            DB::table('user_jpg')
                ->where('user_jpg_id',$input['false'])
                ->delete();
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkUserJPG');
        }
        else
        {
            DB::table('user_jpg')
                ->where('user_jpg_id',$input['false'])
                ->delete();
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkUserJPG');
        }
    }

    public function checkUserEXP()
    {
        $data['userEXP'] = DB::table('user_exp')
            ->orderby('user_exp_status','asc')
            ->paginate(10);
        session(['now_address'=>'/checkUserEXP']);
        return view('admin.hu.checkUserEXP',$data);
    }

    public function userEXPInfo($user_exp_id)
    {
        $data['userEXPInfo'] = DB::table('user_exp')
            ->where('user_exp_id',$user_exp_id)
            ->first();
        return view('admin.hu.userEXPInfo',$data);
    }

    public function changeUserEXP(BaseFunc $baseFunc)
    {
        $input = Input::only('success');
        $value['user_exp_status'] = 1;
        //dd($input);
        DB::table('user_exp')
            ->where('user_exp_id',$input['success'])
            ->update($value);
        $baseFunc->setRedirectMessage(true,'审核通过',NULL,NULL);
        return redirect()->back();
    }

    public function delUserEXP(BaseFunc $baseFunc)
    {
        $input = Input::only('false');
        DB::table('user_exp')
            ->where('user_exp_id',$input['false'])
            ->delete();
        $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkUserEXP');
    }

    public function checkUserArticle()
    {
        $data['userArticle'] = DB::table('user_article')
            ->orderby('user_article_status','asc')
            ->paginate(10);
        session(['now_address'=>'/checkUserArticle']);
        return view('admin.hu.checkUserArticle',$data);
    }

    public function userArticleInfo($id)
    {
        $data['userArticleInfo'] = DB::table('user_article')
            ->where('user_article_id',$id)
            ->first();
        return view('admin.hu.userArticleInfo',$data);
    }

    public function changeUserArticle(BaseFunc $baseFunc)
    {
        $input = Input::only('success');
        $value['user_article_status'] = 1;
        //dd($input);
        DB::table('user_article')
            ->where('user_article_id',$input['success'])
            ->update($value);
        $baseFunc->setRedirectMessage(true,'审核通过',NULL,NULL);
        return redirect()->back();
    }

    public function delUserArticle(BaseFunc $baseFunc)
    {
        $input = Input::only('false');
        DB::table('user_article')
            ->where('user_article_id',$input['false'])
            ->delete();
        $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/checkUserArticle');
    }
}